package com.nth.android.ar;

public class ARCamera {

	public static final float DEFAULT_VIEW_ANGLE = (float) Math.toRadians(30);

	public int width, height;

	public Matrix3 transform = new Matrix3();
	public Vector3 lco = new Vector3();

	float viewAngle;
	float dist;

	public ARCamera(int width, int height) {
		this.width = width;
		this.height = height;

		transform.toIdentity();
		lco.set(0, 0, 0);

		setViewAngle(DEFAULT_VIEW_ANGLE);
	}

	public void setViewAngle(float viewAngle) {
		this.viewAngle = viewAngle;
		this.dist = (this.width / 2) / (float) Math.tan(viewAngle / 2);
	}

	public void setViewAngle(int width, int height, float viewAngle) {
		this.viewAngle = viewAngle;
		this.dist = (width / 2) / (float) Math.tan(viewAngle / 2);
	}

	public void projectPoint(Vector3 orgPoint, Vector3 prjPoint, float addX, float addY) {
		prjPoint.x = dist * orgPoint.x / -orgPoint.z;
		prjPoint.y = dist * orgPoint.y / -orgPoint.z;
		prjPoint.z = orgPoint.z;
		prjPoint.x = prjPoint.x + addX + width / 2;
		prjPoint.y = -prjPoint.y + addY + height / 2;
	}

	@Override
	public String toString() {
		return "CAM(" + width + "," + height + ")";
	}

}
